<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>DWR学习</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type='text/javascript' src='dwr/interface/HelloWorld.js'> </script>
  <script type='text/javascript' src='dwr/engine.js'> </script>
  <script type='text/javascript' src='dwr/util.js'> </script>
  <script type="text/javascript">
  
  function submitUser() {
  	var user = dwr.util.getValue("userName");
	HelloWorld.hello(user, function(value) {
	    dwr.util.setValue("messageFromServer", value);
	});
  }
  
  function hadVisted(){
  	HelloWorld.hadVisted(function(value){
  		dwr.util.setValue("messageFromServer", value);
  	});  
  }
  
  function sendAndReceiveObject(){
  	var object = {};
  	object.name="hecongqi";
  	object.password="123456";
  	HelloWorld.sendAndReceiveObject(object,function(u){
  		for(var property in u){ 
            alert(property+":"+u[property]); 
        } 
  	})
  }
  
  function sendAndReceiveList(){
  	var array = [];
  	var user1 = {name:'甲',password:'jia'};
  	var user2 = {name:'乙',password:'yi'};
  	array.push(user1);
  	array.push(user2);
  	HelloWorld.sendAndReceiveList(array,function(returnArray){
  		var length = returnArray.length;
  	});
  }
  
  function sendAndReceiveMap(){
  	var map = {};
  	map.key='value';
  	HelloWorld.sendAndReceiveMap(map,function(returnMap){
  		var value = returnMap.key;
  	});
  }
  
  </script>
</head>

<body>
	<input type="text" id="userName"/>
	<input type="button" value="提交" onclick="submitUser()";/><br/>	
	<input type="button" value="点一下，测试我是否点过" onclick="hadVisted()";/>	<br/>
	<input type="button" value="往后台发送/接收对象" onclick="sendAndReceiveObject()";/><br/>	
	<input type="button" value="往后台发送/接收列表" onclick="sendAndReceiveList()";/><br/>	
	<input type="button" value="往后台发送/接收映射" onclick="sendAndReceiveMap()";/><br/>	
	<br/><br/>
	<textarea id="messageFromServer" rows="10" cols="30"></textarea>
</body>
</html>
